<?
include("common/header.html");
include("common/left.html");
include("common/areaCode.inc.php");
// print_r($areaCode);
// 获取所有
$sql="SELECT id,dname,getPY(dname,1) as py FROM pft_member WHERE dtype<2 AND status=0 order by py";
$GLOBALS['le']->query($sql);
$select1 = '<select style="width:120px" name="city_agent[]" class="agents"><option value="0">请选择代理商</option>';
$select2 = '<select style="width:120px"><option value="0">请选择代理商</option>';
while($row=$GLOBALS['le']->fetch_assoc()){
    if(empty($row['dname'])) continue;
    $select1.='<option value="'.$row['id'].'">'.$row['py'].'-'.$row['dname'].'</option>';
    $select2.='<option value="'.$row['id'].'">'.$row['py'].'-'.$row['dname'].'</option>';
}
$select1.='</select>';
$select2.='</select>';
// exit;
?>
<title><?=$ltitle?></title>
<link rel="stylesheet" type="text/css" href="css/distri.css"/>
<link rel="stylesheet" type="text/css" href="css/jump.css"/>
<script type="text/javascript" src="js/jquery.getareas.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    // $(".ui-select").change(function(){
        // index = $(".ui-select").index($(this));
        // $(".ui-select").eq(index+1).show();
    // });
    (function(){
        $(".agents").val('2093');
        // $(".agents option[text='2093']").attr("selected", true)
    })();
    
    $(".province").change(function(){
        _this = $(this);
        flag = false;
        $(".selected").each(function(){
            if($(this).attr("data")==_this.val()) flag = true;
            
        });
        if(flag) return false;
        $.getJSON('call/jh_alliance.php',{action:'getProvince',keys:$(this).val()},function(data){
            _ds = data.key;
            _html = '<li class="itemLi odd selected" data="'+_ds+'">';
            _html +='<ul class="topUl">';
            _html +='<li class="tcol_1 tcol">'+data.title+'</li>';
            _html +='<li class="tcol_2 tcol">';
            _html +='';
            _html +='</li>';
            _html +='</ul>';
            _html +='<div class="botW clearfix">';
            _html +='<table class="table">';
            _html +='<thead>'
            _html +='<tr>';
            _html +='<th class="tbcol tbcol_1">地点</th>';
            _html +='<th class="tbcol tbcol_2">代理商账号</th>';
            _html +='</tr>';
            _html +='</thead>';
            _html +='<tbody>';
            
            for(var i in data.city){
                // alert(data.city[i].code);
                console.log(data.city[i].ctitle);
                _html +='<tr>';
                _html +='<input type="hidden" name="city_code[]" value="'+data.city[i]+'"/>';
                _html +='<td class="tname tbcol_1">'+data.city[i].ctitle+'</td>';
                _html +='<td data="'+_ds+'" class="agent_se" agent="'+data.city[i].inviter+'">';
                _html +=$("#hideSetion").html();
                _html +='</td>';
                _html +='</tr>';
            }
            _html +='</tbody>';
            _html +='</table>';
            _html +='<a href="#" class="slideUpBtn"><i class="i">︽</i>收起</a>';
            _html +='</div>';
            _html +='</li>';
             $(".listWrap").html(_html);
            //$(".listWrap").append(_html);
            // alert(.length);
            $(".agent_se").each(function(idx,element){
                // alert($(this).attr("agent"));
                if($(this).attr("data")==_ds && $(this).attr("agent")){
                    $(this).find(".agents").val(Number($(this).attr("agent")));
                    // alert($(this).find(".province").attr("name"));
                }
            });
        });
    });
});;
</script>
<link type="text/css" rel="stylesheet" href="css/alliance_m.css" />
<style type="text/css">
.mc_title a{float:right; margin-right:20px; line-height:25px;}
.dismtab tbody td.txtlf{ text-align:left; padding-left:8px;}
.ui-t-add{background:url(images/img_add.gif) left center no-repeat; padding-left:20px; margin-right:10px;}
.ui-c-box{float:left;margin-top: 25px;border:1px solid #DEDEDE;padding:20px;color: #333333;width: 100%;}
.ui-line{margin-bottom:10px;}
.ui-title{font-size: 14px;color: #445269;width:120px;display:inline-block;}
.ui-select{width:120px;}
.hide{display:none;}
.ui-list{border:1px solid red;width:100%;}
</style>
<div style="display:none;" id="hideSetion">
<?=$select1;?>
</div>

<!-- <iframe name="ifr" style="display:block;"></iframe> -->
<form action="call/jh_alliance.php" method="post" target="ifr">
<input type="hidden" name="action" value="setAgent"/>
<div class="r_content">
    <h3 class="mc_title">
    <a href="javascript:void(0);" target="_blank">联盟管理</a>
    <a href="javascript:void(0);" target="_blank" class="ui-t-add">添加分销商</a>
    <span class="mctit_1"><span class="mctit_2">联盟管理</span></span>
    </h3>
    <div class="ui-c-box">
        <p class="ui-line">
            <span class="ui-title">代理商配置：</span>
            <span >
                <select class="ui-select province">
                    <option>请选择代理省份</option>
                    <?foreach($areaCode as $k => $province):?>
                    <option value="<?=$k?>"><?=$province['title']?></option>
                    <?endforeach;?>
                </select>
            </span>
        </p>
        <div class="listWrap">
            <ul id="mlistUl" class="listUl">
               <li class="loading hide" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">加截数据...</p><img src="images/other/loading_1.gif" alt="" /></li>
               <?foreach($areaCode as $k => $province):?>
               <?if($k>0) continue;?>
               <li class="itemLi odd  selected">
                <ul class="topUl">
                    <li class="tcol_1 tcol"><?=$province['title']?></li>
					<li class="tcol_2 tcol">
                        <?=$select2?>
                    </li>
                </ul>
                <div class="botW clearfix">
                    <table class="table">
                    <thead>
                    <tr>
                        <th class="tbcol tbcol_1">地点</th>
                        <th class="tbcol tbcol_2">代理商账号</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?foreach($province['city'] as $key => $city):?>
                    <tr>
                        <input type="hidden" name="city_code[]" value="<?=$key?>"/>
                        <td class="tname tbcol_1"><?=$city?></td>
                        <td>
							<?=$select1?>
                        </td>
                    </tr>
                    <?endforeach;?>
                    </tbody>
                    </table>   
                    <a href="#" class="slideUpBtn"><i class="i">︽</i>收起</a>
                </div>
                </li>
                <?endforeach;?>
                <li><input type="submit" class="l_save" value="保存"></li>
            </ul>
        </div>
    </div>
</div>